#ifndef     __HEAT_TASK_H
#define     __HEAT_TASK_H

#include "../rtos/thread.h"
#include "../rtos/message_queue.h"
#include "../utils/object.h"

namespace task {

class HeatTask : public rtos::Thread<HeatTask, 1024, osPriorityHigh2> {

public:

    enum class State : uint8_t {
        IDLE = 0,
        WORK = 1,
        TIMEOUT = 2,
        TEMP_FAIL = 3,
        STOP = 4,
    };

    void run();

    uint8_t state() { return static_cast<uint8_t>(m_state); }

    void reset() { m_mq.post(State::IDLE); }
    void stop() { m_mq.post(State::STOP); }

private:
    bool await(uint32_t timeout = osWaitForever);

    void do_idle();
    void do_work();
    void do_fail();
    void do_timeout();

    rtos::MessageQueue<State, 2> m_mq;
    State m_state = State::IDLE;
};

inline utils::Object<HeatTask> heatTask;

}



#endif
